// pages/addAddress/addAddress.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    region: ['广东省', '广州市', '海珠区'],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },
  bindRegionChange: function (e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({
      region: e.detail.value
    })
  },
  submitForm:function(e){
    var that=this;
    var name=e.detail.value.name;
    var phone=e.detail.value.phone;
    var uaddress=e.detail.value.uaddress;
    var region=that.data.region;
    var province=region[0];
    var city=region[1];
    var county=region[2];
    var uid=wx.getStorageSync('uid');
    if(name != "" && phone != "" && uaddress != ""){
      var param = {
        uid: uid,
        name:name,
        phone:phone,
        province:province,
        city:city,
        area:county,
        uaddress:uaddress
      }
      app.wxRequest('POST', "Index/addAddressInfo", param, (res) => {
        var code = res.code;
        if(code == 1){
          wx.showToast({
            title: '添加成功',
            icon:"none",
            mask:true,
            duration:1500
          })
          setTimeout(function(){
            wx.navigateBack({
              
            })
          },1500)
        }else{
          wx.showToast({
            title: '操作失败,请重试',
            icon:"none",
            duration:1500
          })
        }
  
      }, (err) => {
        console.log(err.errMsg)
      })
    }else{
      wx.showToast({
        title: '请认真填写信息',
        icon:"none",
        duration:1500
      })
    }

    console.log(e)
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})